#include "OP_Hide.h"

using namespace std;
using namespace CICore;
using namespace CIGeom;
using namespace CIView;

///<************************************************************************************************************>
///<************************************* region CONSTANTS DEFINITION ******************************************>
///<************************************************************************************************************>

/***************************************************************************************************************
************************************** endregion CONSTANTS DEFINITION ******************************************
****************************************************************************************************************/












/// <summary> 
/// Constructor 
/// </summary>
/// <param name="v"> A reference to the vector that contains the four 3D views pointers </param>
CIOps::OP_Hide::OP_Hide (vector<CIView::View*>& v)
: Operation (v) {
}

/// <summary> 
/// Destructor 
/// </summary>
CIOps::OP_Hide::~OP_Hide() {}




///<************************************************************************************************************>
///<**************************************** region Utility Methods ********************************************>
///<************************************************************************************************************>

/// <summary> 
/// Method called to execute directly the operation 
/// </summary>
/// <returns> The operation status </returns>
int CIOps::OP_Hide::Exec() {
    
    if (scene.GetGeometries().empty()) {
        status = ZOMBIE;
        return status; 
    }

    bool hasPrimitivesSelected = SaveOldSelection();                             //Saves the old selection status

    if (!hasPrimitivesSelected) {                   //If there's no primitive selected
        status = ZOMBIE;                            //the execution of the operation doesn't make sense
        return status;                              //so it must return
    }

    status = COMPLETED;

    HideSelected();

    RestoreFeedbackPosition();                      //Restores feedback position

    UpdateViews();                                  //Updates the 3D views    

    return status;        
}

/// <summary> 
/// Method called to undo the operation 
/// </summary>
void CIOps::OP_Hide::Undo() {
    status = UNDO;

    RestoreOldVisibility();     //Restore old visibility status
    UpdateViews();              //Updates the 3D views
}

/// <summary> 
/// Method called to redo the operation 
/// </summary>
void CIOps::OP_Hide::Redo() {
    status = COMPLETED;

    HideSelected();

    RestoreFeedbackPosition();                      //Restores feedback position

    UpdateViews();                                  //Updates the 3D views  
}

/// <summary> 
/// Mouse Pressed event handler, called whenever the operation 
/// is in execution and a 3D view intercepts a mouse press event
/// </summary>
/// <param name="view"> The view that has thrown the event </param>
/// <param name="e"> Mouse Pressed event </param>
void CIOps::OP_Hide::MousePressEvent (CIView::View* view, QMouseEvent* e) {
}

/// <summary> 
/// Mouse Released event handler, called whenever the operation 
/// is in execution and a 3D view intercepts a mouse release event
/// </summary>
/// <param name="view"> The view that has thrown the event </param>
/// <param name="e"> Mouse Released event </param>
void CIOps::OP_Hide::MouseReleaseEvent (CIView::View* view, QMouseEvent* e) {
}

/// <summary> 
/// Mouse Moved event handler, called whenever the operation 
/// is in execution and a 3D view intercepts a mouse move event
/// </summary>
/// <param name="view"> The view that has thrown the event </param>
/// <param name="e"> Mouse Moved event </param>
void CIOps::OP_Hide::MouseMoveEvent (CIView::View* view, QMouseEvent* e) {
}

/// <summary> 
/// Wheel event handler, called whenever the operation 
/// is in execution and a 3D view intercepts a mouse wheel event
/// </summary>
/// <param name="view"> The view that has thrown the event </param>
/// <param name="e"> Wheel event </param>
void CIOps::OP_Hide::WheelEvent (CIView::View* view, QWheelEvent* e) {
}


/// <summary> 
/// Method called to hide the selected primitives 
/// </summary>
void CIOps::OP_Hide::HideSelected() {
    switch (scene.GetSelectionMode()) {             //According to the current selection mode
        case Geometry::VERTICES_SELECTION:          
            scene.HideSelectedVertices();           //hides all selected vertices
            break;

        
        case Geometry::FACES_SELECTION:             
            scene.HideSelectedFaces();              //hides all selected faces
            break;
    }

    views[0]->SetPrimitivesSelected (false);
}
/***************************************************************************************************************
***************************************** endregion Utility Methods ********************************************
****************************************************************************************************************/
